using AutoMapper;
using Domain.Models;
using IRepository;
using IServices;
using Services.Base;
using System.Collections.Generic;
using ViewModel.CompanyModel;

namespace Services
{
    public class CompanyService : BaseService<Company>, ICompanyService
    {
        protected readonly ICompanyRepository companyRepository;

        public CompanyService(ICompanyRepository companyRepository, IMapper mapper) : base(mapper)
        {
            this.companyRepository = companyRepository;
            base.baseRepository = companyRepository;
        }

        public int CreateCompany(CreateCompanyModel model)
        {
            var entity = mapper.Map<Company>(model);
           var result = companyRepository.Add(entity);
            if (result > 0)
            {
                return entity.Id;
            }
            return -1;
        }

        public IEnumerable<Company> GetCompanies()
        {
            return this.companyRepository.Query();
        }

        public Company GetCompany(int id)
        {
            return this.companyRepository.QueryById(id);
        }
    }

}